/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.cip.esymons.eventos.bc;

import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import org.cip.esymons.general.bc.ComiteLocalFacadeLocal;
import org.cip.esymons.general.be.ComiteLocal;

/**
 *
 * @author OscarA
 */
public class ComiteLocalDelegate {

    ComiteLocalFacadeLocal local;

    public ComiteLocalDelegate() {
        local = lookupComiteLocalFacade();
    }

    private ComiteLocalFacadeLocal lookupComiteLocalFacade() {
        try {
            Context c = new InitialContext();
            return (ComiteLocalFacadeLocal) c.lookup("java:comp/env/ComiteLocalFacade");
        } catch (NamingException ne) {
            Logger.getLogger(getClass().getName()).log(Level.SEVERE, "exception caught", ne);
            throw new RuntimeException(ne);
        }
    }

    public List<ComiteLocal> listarComitesLocales() throws Exception {
        try {
            return local.findAll();
        } catch (Exception e) {
            local = lookupComiteLocalFacade();
            throw new Exception(e.getStackTrace().toString(), e);
        }
    }

    public ComiteLocal buscarComitesLocales(int id) throws Exception {
        try {
            return local.find(id);
        } catch (Exception e) {
            local = lookupComiteLocalFacade();
            throw new Exception(e.getStackTrace().toString(), e);
        }
    }

    public List<ComiteLocal> listarXConsDepartamental(int id) throws Exception {
        try {
            return local.listarxConsejoDepartamental(id);
        } catch (Exception e) {
            local = lookupComiteLocalFacade();
            throw new Exception(e.getStackTrace().toString(), e);
        }
    }

    public void crearComiteLocal(ComiteLocal a) throws Exception {
        try {
            local.create(a);
        } catch (Exception e) {
            local = lookupComiteLocalFacade();
            throw new Exception(e.getStackTrace().toString(), e);
        }
    }
}
